﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using BlueLotus7.Common;

namespace BlueLotus7
{
    public class ValueAuditing : IValidate
    {
        string fieldIdentity;
        string oldValue;
        string newValue;

        public string FieldIdentity
        {
            get { return fieldIdentity; }
        }
        public string OldValue
        {
            get
            {
                return oldValue;
            }
            set
            {
                oldValue = value;
            }
        }
        public string NewValue
        {
            get
            {
                return newValue;
            }
            set
            {
                newValue = value;
            }
        }

        public ValueAuditing(string fieldIdentity)
        {
            this.fieldIdentity = fieldIdentity;
        }

        public ValueAuditing(string fieldIdentity, string oldValue, string newValue)
        {
            this.fieldIdentity = fieldIdentity;
            this.oldValue = oldValue;
            this.newValue = newValue;
        }

        #region IValidate 成员

        public bool IsValid
        {
            get
            {
                try
                {
                    Validate();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }

        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(fieldIdentity))
            {
                throw new NullOrEmptyStringException("fieldIdentity");
            }
            else if (oldValue == newValue)
            {
                throw new InvalidObjectException("ValueAuditing");
            }
        }

        #endregion
    }
}
